import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Gao zhao xu
 * Date: 2023-11-14
 * Time: 20:31
 */
public class TestSet {
    public static void main(String[] args) {
        Set<String> strings = new TreeSet<>();
        strings.add("hello");
        strings.add("abcd");
        strings.add("def");
        //set当中的元素是不可以重复的，加两次第二次会失效
        //TreeSet的底层是TreeMap
        strings.add("def");
        //迭代器遍历（ArrayList也讲过）
        Iterator<String> iterator = strings.iterator();
        while (iterator.hasNext()) System.out.print(iterator.next() + " ");
        System.out.println();
        //直接遍历：
        for (String x: strings) System.out.print(x + " ");
        System.out.println();
    }
}
